SupeLogo

Difficulty:

Picking Numbers Game

Category: Binary SearchLevel: 3
Status:

Bob and Alice are playing a game involving an infinite series of numbers: 1,2,3, …

  1. 1. Alice wants to select a numbers from this series.
  2. 2. Bob wants to select b numbers from this series.

However, there are some conditions:

  1. 1. Alice can only choose numbers that are not divisible by 𝑐.
  2. 2. Bob can only choose numbers that are not divisible by 𝑑.
  3. 3. Alice and Bob cannot pick the same number.

Your task is to determine the smallest number n such that Alice and Bob can each pick their respective numbers from the infinite series without violating any conditions.


Example 1:

Input: a = 3, b = 2, c = 2, d = 3
Output: 5
Explanation: Alice can choose numbers not divisible by 2: {1, 3, 5}
Bob can choose numbers not divisible by 3: {2, 4}
The smallest number n such that Alice and Bob can each choose their respective numbers without overlap is 5.

Example 2:

Input: a = 4, b = 3, c = 3, d = 4
Output: 7


Constraints:

  • 1 <= a, b <= 10^9
  • 1 < c, d <= 1000


Loading...

    Test Cases

    1test('TestCase1', () => { 2 expect(minNumberForPicks(3, 2, 2, 3)).toBe(5); 3});
    1test('TestCase2', () => { 2 expect(minNumberForPicks(4, 3, 3, 4)).toBe(7); 3});
    1test('TestCase3', () => { 2 expect(minNumberForPicks(3, 2, 3, 3)).toBe(7); 3});

    Console